package kibahed.uni.charts;

import java.util.LinkedList;
import java.util.List;

import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class XYDataPairList {

	private String type;
	private String algorithm;

	private double[] yValues = null;

	@XmlAnyElement(lax = true)
	private List<XYDataPair> datapairs;

	public XYDataPairList() {
		datapairs = new LinkedList<XYDataPair>();
	}
	
	public XYDataPairList(XYDataPairList father) {
		datapairs = new LinkedList<XYDataPair>(father.datapairs);
		type = father.type;
		algorithm = father.algorithm;
	}

	public void addXYDataPair(XYDataPair pair) {
		datapairs.add(pair);
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getAlgorithm() {
		return algorithm;
	}

	public void setAlgorithm(String algorithm) {
		this.algorithm = algorithm;
	}

	public double[] getYValues() {

		if (yValues == null) {
			yValues = new double[datapairs.size()];
			for (int i = 0; i < datapairs.size(); i++) {
				yValues[i] = datapairs.get(i).getyValue();
			}
		}
		return yValues;
	}

	public double[] getXValues() {
		double[] xValues = new double[datapairs.size()];
		for (int i = 0; i < datapairs.size(); i++) {
			xValues[i] = (double) (datapairs.get(i).getxValue());
		}
		return xValues;
	}
}
